package com.controller.hht;

import com.bean.ydq.StuInfo;
import com.config.Result;
import com.service.LoginstuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class LoginstuController {
    @Resource
    private LoginstuService loginstuService;
    /**
     * 学员登陆
     * @param account
     * @param password
     * @param wxid
     * @param request
     * @return
     */
    @RequestMapping(value = "loginstu",method = RequestMethod.GET)
    public Result loginstu(@RequestParam(value = "account")String account, @RequestParam(value = "password")String password, @RequestParam(value = "wxid")String wxid, HttpServletRequest request) throws ParseException {
        //获取当前时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd");
        String nowdate = simpleDateFormat.format(new Date());
        Date setdate = simpleDateFormat.parse("06-01");

        System.out.println(nowdate);
        if(simpleDateFormat.parse(nowdate).getTime()<=setdate.getTime()){
            StuInfo stuinfo=loginstuService.stuLogin(account,password);
            if (stuinfo!= null){
                String stu_wxid=stuinfo.getWxid();
                if(wxid.equals(stu_wxid)){
                    request.getSession().setAttribute("session_user",stuinfo);
                    return new Result("登录成功!");
                }
                else return new Result("账户或密码错误!");
            }
            else{
                 return new Result("账户或密码错误!");
           }
        }
        else return new Result("超过规定时间登录!");
    }
}
